home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Toolbox / ItemHider / MPW / MultiHider / MultiHider.p < prev    next >
Encoding:
Text File  |  1992-07-15  |  3.3 KB  |  129 lines  |  [TEXT/MPS ]

  1. PROGRAM MultiHider;
  2.  
  3. USES Memtypes, QuickDraw, OSIntf, ToolIntf, PackIntf;
  4.  
  5. CONST
  6.    itemOK =       7;
  7.    itemCancel =   8;
  8.    itemStat1 =    1;
  9.    itemStat2 =    3;
  10.    itemStat3 =    4;
  11.    itemEdit1 =    2;
  12.    itemEdit2 =    5;
  13.    itemEdit3 =    6;
  14.    itemHider =    9;
  15.    itemHideIt =   10;
  16.    itemMax =      10;
  17. VAR
  18.    ihDialog:   DialogPtr;
  19.    itemHit:    INTEGER;
  20.    theType:    INTEGER;
  21.    theHdl:     Handle;
  22.    theBox:     Rect;  
  23.    hidden:     BOOLEAN;
  24.  
  25.  
  26. PROCEDURE MyDrawItem(dlg: DialogPtr; theItem: INTEGER);
  27. VAR
  28.    iType:   INTEGER;
  29.    iBox:    Rect;
  30.    iHdl:    Handle;
  31.    iIndex:  INTEGER;
  32.  
  33. BEGIN
  34.    GetDItem(dlg, theItem, iType, iHdl, iBox);
  35.    IF hidden THEN BEGIN
  36.       PenMode(notPatBic);
  37.       PenPat(gray);
  38.       BackPat(gray);
  39.       PaintRect(iBox);
  40.       FrameRect(iBox);
  41.       
  42.       PenMode(patCopy);
  43.       PenPat(black);
  44.       BackPat(white);
  45.       PenNormal;
  46.    END;
  47. END;
  48.  
  49.  
  50. PROCEDURE HideEditItem(theDialog: DialogPtr; theItem: INTEGER);
  51. VAR
  52.    iIndex:  INTEGER;
  53. BEGIN
  54.    (* Get the item information. *)
  55.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  56.    
  57.    (* Now check to see if it is the current text item.   *)
  58.    IF DialogPeek(theDialog)^.EditField + 1 = theItem THEN BEGIN
  59.       (* It is, so now we find the next editText item    *)
  60.       (* in the item list.  Start with the one we are on.*)
  61.       iIndex := theItem;
  62.       REPEAT
  63.          (* Increment to the next item, and make sure we *)
  64.          (* don't run off the end of the item list.      *)
  65.          iIndex := iIndex + 1;
  66.          IF iIndex > itemMax THEN iIndex := 1;
  67.          GetDItem(theDialog, iIndex, theType, theHdl, theBox);
  68.  
  69.          (* Keep going until we find an editText item.   *)
  70.          (* NOTE: THIS CODE ASSUMES THERE IS MORE THAN   *)
  71.          (*       ONE editText ITEM IN THE DIALOG.       *)
  72.       UNTIL (theType = editText);
  73.       SelIText(theDialog, iIndex, 0, 0);
  74.    END;
  75.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  76.    SetDItem(theDialog, theItem, statText, theHdl, theBox);
  77.    DrawDialog(theDialog);
  78. END;
  79.  
  80.  
  81. PROCEDURE ShowEditItem(theDialog: DialogPtr; theItem: INTEGER);
  82. VAR
  83.    oldPort: GrafPtr;
  84. BEGIN
  85.    GetPort(oldPort);
  86.    SetPort(theDialog);
  87.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  88.    SetDItem(theDialog, theItem, editText, theHdl, theBox);
  89.    InvalRect(theBox);
  90.    DrawDialog(theDialog);
  91.    SetPort(oldPort);
  92. END;
  93.  
  94.  
  95. BEGIN {main program}
  96.    InitGraf (@thePort);          {the big five inits}
  97.    InitFonts;
  98.    InitWindows;
  99.    TEInit;
  100.    InitDialogs (nil);
  101.  
  102.    hidden := FALSE;
  103.  
  104.    ihDialog := GetNewDialog(128, NIL, WindowPtr(-1));
  105.    GetDItem(ihDialog, itemHider, theType, theHdl, theBox);
  106.    SetDItem(ihDialog, itemHider, theType, @MyDrawItem, theBox);
  107.    ShowWindow(ihDialog);
  108.    
  109.    itemHit := 0;
  110.    WHILE ((itemHit <> itemOK) AND (itemHit <> itemCancel)) DO BEGIN
  111.       ModalDialog(nil, itemHit);
  112.       CASE itemHit OF
  113.          itemHideIt: BEGIN
  114.             GetDItem(ihDialog, itemHit, theType, theHdl, theBox);
  115.             hidden := NOT hidden;
  116.             IF hidden THEN BEGIN
  117.                SetCtlValue(ControlHandle(theHdl), 1);
  118.                HideEditItem(ihDialog, itemEdit2);
  119.             END ELSE BEGIN
  120.                SetCtlValue(ControlHandle(theHdl), 0);
  121.                ShowEditItem(ihDialog, itemEdit2);
  122.             END;
  123.          END;
  124.       END;
  125.    END;
  126.  
  127.    DisposDialog(ihDialog);
  128. END.
  129.